//
//  MyFlowTow.m
//  BuffetNews
//
//  Created by weidawei on 14-11-5.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "MyFlowTow.h"

@interface MyFlowTow ()

@property (nonatomic, retain) NSMutableArray * arr;
@end


@implementation MyFlowTow

- (void)prepareLayout
{
    [super prepareLayout];
    CGFloat width  = self.collectionView.frame.size.width;
    CGFloat height = self.collectionView.frame.size.height;
    // 1.获取collectionView有多少个section
    NSInteger sectionNumber = [self.collectionView numberOfSections];
    [self.collectionView reloadData];
    //2. 获取每个section的item数
    self.arr = [[NSMutableArray alloc] init];
    for (int i = 0; i < sectionNumber; i++) {
        NSInteger itemNumber = [self.collectionView numberOfItemsInSection:i];
        
        for (int j = 0; j < itemNumber; j++) {
            
            // 在这个循环中对某一个确定的cell安排布局
            
            // 布局属性类 ， 作用 对应某一个cell，单独给cell安排布局
            NSIndexPath *indexPath = [NSIndexPath indexPathForItem:j inSection:i];
            
            UICollectionViewLayoutAttributes *attribute = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
             attribute.frame = CGRectMake(1, height / 7 + 20 , width / 2 - 2, height / 7  - 1);
            
            
            if (j  == 1) {
                attribute.frame = CGRectMake(width / 2, height / 7 + 20, width / 2 - 1 , height / 7 - 1);
                
            }
            
            if (j == 2) {
                attribute.frame = CGRectMake(1, height / 7 * 2 + 21, width / 2 - 2,  height / 7 - 1);
            }
            
            if (j == 3) {
                attribute.frame = CGRectMake(width / 2 , height / 7 * 2 + 21, width / 2 - 1, height / 7  - 1);
            }
            if (j == 4) {
                attribute.frame = CGRectMake(1, height / 7 * 3 + 22, width - 2, height / 7 * 2 + 24);
            }
            if (j == 5) {
                attribute.frame = CGRectMake(1, height / 7 * 5 + 48, width - 2, height / 7 - 1);
            }
            // 对attribute进行设置
            // ..
            
            [self.arr addObject:attribute];
            
        }
    }
}
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    return self.arr;
}

- (void)dealloc
{
    [_arr release];
    [super dealloc];
}



@end
